import allure
from selenium.webdriver.common.by import By
from base.base_page import BasePage


class  Page_register(BasePage):
    # 点击注册按钮
    @allure.step("点击注册按钮")
    def __click_register_button(self):
        self.click_mouse((By.XPATH,"//span[contains(text(),'立即注册')]"))

    # 输入用户名
    @allure.step("输入手机号")
    def __input_phone(self,phone):
        self.input_page_element((By.CSS_SELECTOR,"#username"),phone)
    # 输入验证码
    @allure.step("输入验证码")
    def __input_verify_code(self,verify_code):
        self.input_page_element((By.CSS_SELECTOR,"input[placeholder='图像验证码']"),verify_code)

    # 输入密码1
    @allure.step("输入密码1")
    def __input_password1(self,password1):
        self.input_page_element((By.CSS_SELECTOR,"#password"),password1)
    # 输入密码2
    @allure.step("输入密码2")
    def __input_password2(self,password2):
        self.input_page_element((By.CSS_SELECTOR,"#password2"),password2)

    # 输入推荐人手机
    @allure.step("输入推荐人手机")
    def __input_invite(self,invite):
        self.input_page_element((By.XPATH,"//input[@name='invite']"),invite)

    # 获取点击注册按钮后的文本
    @allure.step("获取点击注册按钮后的文本")
    def get_register_text(self):
        return self.get_page_element_text((By.CSS_SELECTOR,".layui-layer-content.layui-layer-padding"))

    # 点击同意注册按钮
    @allure.step("点击同意注册按钮")
    def __click_agree_button(self):
        self.click_mouse((By.XPATH,"//a[contains(text(),'同意协议并注册')]"))

    @allure.step("点击注册")
    def register(self,phone,verify_code,password1,password2,invite):
        self.__click_register_button()
        self.__input_phone(phone)
        self.__input_verify_code(verify_code)
        self.__input_password1(password1)
        self.__input_password2(password2)
        self.__input_invite(invite)
        self.__click_agree_button()

